home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / C++ Toolbox 1.0 / QuickDraw++.h < prev    next >
C/C++ Source or Header  |  1996-05-28  |  3KB  |  210 lines

  1. #pragma once
  2. /*
  3.     File:        QuickDraw++.h
  4.     
  5.     Contains:    C++ extensions to QuickDraw.
  6.     
  7.     Version:    1.0
  8.     
  9.     Copyright:    ©1995 Chris K. Thomas.  All Rights Reserved.
  10. */
  11.  
  12. //int operator+=(const int &, const int&);
  13.  
  14. #include "Types++.h"
  15. #include "Memory++.h"
  16.  
  17. //
  18. // Rectangle class - encapsulate a Mac Rect structure
  19. //
  20.  
  21. struct Rectangle
  22. {
  23.     short top, left, bottom, right;
  24.     
  25.     //
  26.     // constructors
  27.     //
  28.     Rectangle()
  29.     {
  30.         top = 0;
  31.         left = 0;
  32.         right = 0;
  33.         bottom = 0;
  34.     }
  35.     
  36.     Rectangle(Rect &inRect)
  37.     {
  38.         top = inRect.top;
  39.         left = inRect.left;
  40.         right = inRect.right;
  41.         bottom = inRect.bottom;
  42.     }
  43.     
  44.     //
  45.     // geometry accessors
  46.     //
  47.     long width()
  48.     {
  49.         return right - left;
  50.     }
  51.     
  52.     long height()
  53.     {
  54.         return bottom - top;
  55.     }
  56.     
  57.     void hMoveTo(long inOffset)
  58.     {
  59.         hMoveDelta(-left + inOffset);
  60. //        hMoveDelta(inOffset);
  61.     }
  62.     
  63.     void vMoveTo(long inOffset)
  64.     {
  65.         vMoveDelta(-top + inOffset);
  66.     }
  67.     
  68.     void hMoveDelta(long inOffset)
  69.     {
  70.         left += inOffset;
  71.         right += inOffset;
  72.     }
  73.     
  74.     void vMoveDelta(long inOffset)
  75.     {
  76.         top += inOffset;
  77.         bottom += inOffset;
  78.     }
  79.     
  80.     void setSizeFromTopLeft(long inHSize, long inVSize)
  81.     {
  82.         right = left + inHSize;
  83.         bottom = top + inVSize;
  84.     }
  85.     
  86.     long hGetCenter()
  87.     {
  88.         return width()/2 + left;
  89.     }
  90.     
  91.     long vGetCenter()
  92.     {
  93.         return height()/2 + top;
  94.     }
  95.     
  96.     //
  97.     // conversion operator
  98.     //
  99.     
  100.         
  101. //    we’re a real Rect now.
  102.     
  103.     operator Rect()
  104.     {
  105.         return *(Rect *)this;
  106.     }
  107.     
  108.     operator Rect*()
  109.     {
  110.         return (Rect *)this;
  111.     }
  112. };
  113.  
  114. class LStream;
  115.  
  116. class ColorSpecTable
  117. {
  118.     HandleArray<ColorSpec>    mColorTable;
  119.     
  120. public:
  121.     ColorSpecTable(LStream &inTableStream);
  122.     
  123.     Boolean LookupIndexedColor(long inIndex, RGBColor &outColor);
  124. };
  125.  
  126.  
  127. //
  128. // return the center of the end coords. in one dimension
  129. //
  130. inline long CenterPlane(long inStart, long inEnd)
  131. {
  132.     return (((inEnd - inStart)/2) + inStart);
  133. }
  134.  
  135. //
  136. // turn on hilite transfer mode
  137. // only lasts for the duration of the next invert call
  138. //
  139. inline void SetHiliteMode()
  140. {
  141.     LMSetHiliteMode(LMGetHiliteMode() & ~(1 << hiliteBit));
  142. }
  143.  
  144. /*struct ZRGBColor
  145. {
  146.     unsigned short    red;
  147.     unsigned short    green;
  148.     unsigned short    blue;
  149.     
  150.     //
  151.     // notational convenience operators
  152.     //
  153.     bool operator== ( const RGBColor *inRGB1, const RGBColor *inRGB2)
  154.     {
  155.         bool    out = false;
  156.     
  157.         if(        (inRGB1->red == inRGB2->red)
  158.             &&    (inRGB1->green == inRGB2->green)
  159.             &&    (inRGB1->blue == inRGB2->blue))
  160.                 out = true;
  161.         
  162.         return out;
  163.     }
  164. };*/
  165.  
  166. //
  167. // notational convenience operators
  168. //
  169. /*bool operator== ( const RGBColor *inRGB1, const RGBColor *inRGB2)
  170. {
  171.     bool    out = false;
  172.  
  173.     if(        (inRGB1->red == inRGB2->red)
  174.         &&    (inRGB1->green == inRGB2->green)
  175.         &&    (inRGB1->blue == inRGB2->blue))
  176.             out = true;
  177.     
  178.     return out;
  179. }*/
  180.  
  181. // * Metrowerks support for operator overloading is totally broken
  182. inline bool ComparisonOperatorIsFucked ( const RGBColor& inRGB1, const RGBColor &inRGB2)
  183. {
  184.     bool    out = false;
  185.  
  186.     if(        (inRGB1.red == inRGB2.red)
  187.         &&    (inRGB1.green == inRGB2.green)
  188.         &&    (inRGB1.blue == inRGB2.blue))
  189.             out = true;
  190.     
  191.     return out;
  192. }
  193.  
  194. struct StColorSaver
  195. {
  196.     RGBColor fore, back;
  197.     
  198.     StColorSaver()
  199.     {
  200.         GetForeColor(&fore);
  201.         GetForeColor(&back);
  202.     }
  203.     
  204.     ~StColorSaver()
  205.     {
  206.         RGBForeColor(&fore);
  207.         RGBForeColor(&back);
  208.     }
  209.     
  210. };